﻿using System;
using System.Xml.Serialization;
using System.Xml.Serialization.Configuration;
using System.IO;
using System.Net;
using System.Text; 
using seoWebApplication.st.SharkTankDAL.DataCashLib;

namespace seoWebApplication
{
    public partial class webservicecalltest : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            // Prepare StringBuilder for output
            StringBuilder sb = new StringBuilder();
             
            // Display fulfil request
           
         
            sb.AppendLine(WebServiceCall("ReturnProducts").ToString());
            // Output result
            OutputBox.Text = sb.ToString();
        }

        private static string WebServiceCall(string methodName)
        {
            WebRequest webRequest = WebRequest.Create("http://www.shade4sale.com/webservices/authenticateUser.asmx");
            HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
            httpRequest.Method = "POST";
            httpRequest.ContentType = "text/xml; charset=utf-8";
            httpRequest.Headers.Add("SOAPAction: devArticles/" + methodName);
            httpRequest.ProtocolVersion = HttpVersion.Version11;
            httpRequest.Credentials = CredentialCache.DefaultCredentials;
            Stream requestStream = httpRequest.GetRequestStream();
            //Create Stream and Complete Request             
            StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);

            StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
            soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
            soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
            soapRequest.Append("<ReturnProducts  xmlns=\"devArticles\"></ReturnProducts>");
            soapRequest.Append("</soap:Body></soap:Envelope>");

            streamWriter.Write(soapRequest.ToString());
            streamWriter.Close();
            //Get the Response    
            HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
            StreamReader srd = new StreamReader(wr.GetResponseStream());
            string resulXmlFromWebService = srd.ReadToEnd();
            return resulXmlFromWebService;
        }

        private static string WebServiceCall2(string methodName)
        {
            WebRequest webRequest = WebRequest.Create("http://www.shade4sale.com/webservices/authenticateUser.asmx");
            HttpWebRequest httpRequest = (HttpWebRequest)webRequest;
            httpRequest.Method = "POST";
            httpRequest.ContentType = "text/xml; charset=utf-8";
            httpRequest.Headers.Add("SOAPAction: devArticles/" + methodName);
            httpRequest.ProtocolVersion = HttpVersion.Version11;
            httpRequest.Credentials = CredentialCache.DefaultCredentials;
            Stream requestStream = httpRequest.GetRequestStream();
            //Create Stream and Complete Request             
            StreamWriter streamWriter = new StreamWriter(requestStream, Encoding.ASCII);

            StringBuilder soapRequest = new StringBuilder("<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
            soapRequest.Append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ");
            soapRequest.Append("xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>");
            soapRequest.Append("<ReturnEmail xmlns=\"devArticles\">");
            soapRequest.Append("<username>tmoodley</username>");
            soapRequest.Append("</ReturnEmail>");
            soapRequest.Append("</soap:Body></soap:Envelope>");

            streamWriter.Write(soapRequest.ToString());
            streamWriter.Close();
            //Get the Response    
            HttpWebResponse wr = (HttpWebResponse)httpRequest.GetResponse();
            StreamReader srd = new StreamReader(wr.GetResponseStream());
            string resulXmlFromWebService = srd.ReadToEnd();
            return resulXmlFromWebService;
        }
    }
}
